<?php 
include 'connect.php';
?>
<script language="javascript">
function insertimg(strValue){
	document.frmdanhsach.userfile.value=strValue;
	document.frmdanhsach.anhmota.src=strValue;
}
</script>
<script language="javascript">
	//////////////////////////////////////////////////////////////////
	////////////////check all cung cho ADMIN/////////////////////////
	
	function CheckUncheckAll()
{
var i; CheckBoxs=document.getElementsByTagName("input");

for (i=0; i < CheckBoxs.length; i++)
{
if (CheckBoxs[i].type=="checkbox") CheckBoxs[i].checked=document.getElementById("chkAll").checked;
}
}

function checkAllIndustry(ele) {
	var industries = document.forms['frmDanhSach'].elements[ele];
	for (i=0; i < industries.length; i++) industries[i].checked = true;
}
function uncheckAllIndustry(ele) {
	var industries = document.forms['frmDanhSach'].elements[ele];
	for (i=0; i < industries.length; i++) industries[i].checked = false;
}

function checkedJobs(thongbao)
 {
		var e = document.forms['frmdanhsach'];
		var ischeck = 0;
		
		for(i=0; i<e.length; i++) {
			if ( e[i].checked==true && !e[i].disabled )
				ischeck = 1;
		}
		
		if ( ischeck==0 ) {
			alert(thongbao);
			return false;
		} else return true;
	}
function doSaveJobs(Link,thongbao) 
	{
		
		var r;
		var f = document.forms['frmdanhsach'];
		if (checkedJobs(thongbao))
		 {	
		    r = window.confirm('Bạn có chắc chắn không?');		
			if(r)
			{
			f.action = Link;
			f.submit();
			return true;
			}
			else
			return false;
		 }
		 else
		 return false;
	}
function clsText(){
	document.frmdanhsach.userfile.value='';
}

</script>
<script src="../js/checkform.js" type="text/javascript"></script>
<?
function setcheck( $value1, $column1, $value2, $column2, $table)
{
	$setcheck="";
	$strsql2="select * from $table  where $column1='$value1' and $column2='$value2' ";
	$qr12=mysql_query($strsql2);
	$n_record=mysql_num_rows($qr12); 
	if($n_record>0){
	$setcheck ="selected";
	}
	return $setcheck;
}
function randomnumber($soluong)
{
	$today = date("Ymd");
	$i=1;
	$security_code="";
	while($i<=$soluong)
	  {
	  $md5_hash1 = md5(rand(0,999));
	  $code = substr($md5_hash1, 15, 1);
	  $security_code=$security_code.$code;
	  $i++;
	  }
	return $security_code.$today;
}

?><?php 
function showlist($name,$strsql,$ValueField,$DisplayField,$SeletedValue,$strAction,$NameSelect,$style)
{
?>
<select size="1" name=<?php echo $name?>  <?php echo $style?>  onchange= <?php echo $strAction?>  >
             <?php 
			 $qr1=mysql_query($strsql);
			   ?>
          
			<option value="" ><?php echo $NameSelect?></option>
			<?php while($row=mysql_fetch_array($qr1))
			if($SeletedValue==$row[$ValueField])
			{
			?>
             <option value="<?php echo $row[$ValueField]?>" selected><?php echo $row[$DisplayField]?></option>
            <?php }
			else
			{?>
             <option value="<?php echo $row[$ValueField]?>"><?php echo $row[$DisplayField]?></option>
          <?php }?>
</select>
<?php
}
?>
<?php


//Hàm lấy giá trị 1
 function catchinfor($info,$columid,$name,$table)
{
	$qr1=mysql_query("select * from $table where $columid='$info'"); 
	$rowedit=mysql_fetch_array($qr1);
	$nameinfor=$rowedit[$name];
	return $nameinfor;
}
//Hàm lấy giá trị 2
 function catchinfor2($info,$columid,$info2,$columid2,$name,$table)
{
	$qr1=mysql_query("select * from $table where $columid='$info' and $columid2='$info2' limit 0,1"); 
	$rowedit=mysql_fetch_array($qr1);
	$nameinfor=$rowedit[$name];
	return $nameinfor;
}
//Hàm lấy giá trị 3
 function catchinfor3($info,$columid,$info2,$columid2,$name,$table)
{
	$qr1=mysql_query("select * from $table where $columid='$info' and $columid2!='$info2' limit 0,1"); 
	$rowedit=mysql_fetch_array($qr1);
	$nameinfor=$rowedit[$name];
	return $nameinfor;
}

?>
<?php function Checkexits($info,$name,$table)
{
	$qr1=mysql_query("select * from $table where $name='$info'"); 
	$rowedit=mysql_fetch_array($qr1);
	if ($rowedit=="")
	{return false;}
	else
	{return true;}
}
?>
<?php 

function replatestringform($str)
{
	$str =  str_replace(CHR(13),"<br/>",$str);
	return $str;
}
function replatestring($str,$html)
{
	$str= trim(mysql_escape_string($str));
	//$str =  str_replace("'","",$str);
	$str =  str_replace(CHR(92),"",$str);
	$str =  str_replace(CHR(34),"",$str);	
	$str =  str_replace(CHR(13),"",$str);		
	if($html==false)
	{
		$str =  strip_tags($str);
	}
	else
	{
		$str =  str_replace("<script>","",$str);
		$str =  str_replace("</script>","",$str);
		//$str =  str_replace(CHR(10),"<br/>",$str);
	}
	
	return $str;
}
function replatesnoidung($document)
{
	$search = array ('@<xml[^>]*?>.*?</xml>@si',
				'@<style[^>]*?>.*?</style>@si',
				'@<style[^>]*?>.*?</style>@si',
				'@<mce:style[^>]*?>.*?<mce:style>@si',
				'@<![\/\!]*?[^<>]*?>@si',
				'@<w[\/\!]*?[^<>]*?>@si',
				'@</w[\/\!]*?[^<>]*?>@si'
				);
$replace = array ('','','','','','');
$text = preg_replace($search, $replace, $document);
return $text;

}

function checkstring($str,$loai,$length)
{
	$string = str_split($str, $length);
	$str=$string[0];
	if($loai=="email"){$p= "/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{1,4}){1,3}$/";}
	if($loai=="number"){$p= "/^\d{1,13}$/";}
	if($loai=="user"){$p= "/^\w{1,10}$/";}
		if (preg_match($p,$str,$matches)) {
		return true;
		}else{return false;}
	
}


function thongbao($cauthongbao,$link)
{
?>
	<script language="javascript">
	<? if($cauthongbao!=""){?>alert('<?=$cauthongbao?>!');<? }?>
	<? if($link!=""){?>window.location.href='<?=$link?>';<? }?>
	</script>
<? 
}
function make_title_furl($text){
$text= trim($text);
$text = str_replace("'","",$text);
//global $ibforums;
//Charachters must be in ASCII and certain ones aint allowed
$text = html_entity_decode ($text);
$text = preg_replace("/(ä|à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ)/", 'a', $text);
$text = str_replace("ç","c",$text);
$text = preg_replace("/(è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ)/", 'e', $text);
$text = preg_replace("/(ì|í|î|ị|ỉ|ĩ)/", 'i', $text);
$text = preg_replace("/(ö|ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ)/", 'o', $text);
$text = preg_replace("/(ü|ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ)/", 'u', $text);
$text = preg_replace("/(ỳ|ý|ỵ|ỷ|ỹ)/", 'y', $text);
$text = preg_replace("/(đ)/", 'd', $text);
//CHU HOA
$text= trim($text);
$text = preg_replace("/(Ä|À|Á|Ạ|Ả|Ã|Â|Ầ|Ấ|Ậ|Ẩ|Ẫ|Ă|Ằ|Ắ|Ặ|Ẳ|Ẵ)/", 'A', $text);
$text = str_replace("Ç","C",$text);
$text = preg_replace("/(È|É|Ẹ|Ẻ|Ẽ|Ê|Ề|Ế|Ệ|Ể|Ễ)/", 'E', $text);
$text = preg_replace("/(Ì|Í|Ị|Ỉ|Ĩ)/", 'I', $text);
$text = preg_replace("/(Ö|Ò|Ó|Ọ|Ỏ|Õ|Ô|Ồ|Ố|Ộ|Ổ|Ỗ|Ơ|Ờ|Ớ|Ợ|Ở|Ỡ)/", 'O', $text);
$text = preg_replace("/(Ü|Ù|Ú|Ụ|Ủ|Ũ|Ư|Ừ|Ứ|Ự|Ử|Ữ)/", 'U', $text);
$text = preg_replace("/(Ỳ|Ý|Ỵ|Ỷ|Ỹ)/", 'Y', $text);
$text = preg_replace("/(Đ)/", 'D', $text);
$text = preg_replace("/ /", '-', $text);
//Special string
$text = preg_replace("/( |!|#|$|%|')/", '', $text);
//$text = preg_replace("CHR(34)", '', $text);
$text = preg_replace("/(̀|́|̉|$|>|<|=|~|!)/", '', $text);
$text = preg_replace ("'<[\/\!]*?[^<>]*?>'si", "", $text);
$text= trim($text);
$text = str_replace("Đ","D",$text);
$text = str_replace("…","",$text);
$text = str_replace(".","",$text);
$text = str_replace("\"","-",$text);
$text = str_replace("“","-",$text);
$text = str_replace("”","-",$text);
$text = str_replace(" / ","-",$text);
$text = str_replace("/","-",$text);
$text = str_replace(" - ","-",$text);
$text = str_replace("_","-",$text);
$text = str_replace(" ","-",$text);
$text = str_replace( "ß", "ss", $text);
$text = str_replace( "&", "", $text);
$text = str_replace( "%", "", $text);
$text = str_replace( "$", "", $text);
$text = str_replace( "`", "", $text);
$text = str_replace( "^", "", $text);
$text = str_replace( "*", "", $text);
$text = str_replace( "(", "", $text);
$text = str_replace( ")", "", $text);
$text = str_replace( "+", "", $text);
$text = str_replace( ",", "", $text);
$text = str_replace( ";", "", $text);
$text = str_replace( ":", "", $text);
$text = str_replace( "[", "", $text);
$text = str_replace( "]", "", $text);
$text = str_replace( "{", "", $text);
$text = str_replace( "}", "", $text);
$text= trim($text);
//$text = ereg_replace("[^A-Za-z0-9-]", "", $text);
$text = str_replace(CHR(92),"",$text);
$text = str_replace("’","",$text);
$text = str_replace("?","",$text);
$text = str_replace("----","-",$text);
$text = str_replace("---","-",$text);
$text = str_replace("--","-",$text);
$text= trim($text);
return preg_replace('/[^a-zA-Z0-9\-_]/','',$text);
}

function make_title($text){
 $text=str_replace("-"," ",make_title_furl($text));
 return  $text;
}

///HAM CHUYEN CHU HOA ĐẦU DÒNG
function my_ucfirst($string, $e ='utf-8') {
    if (function_exists('mb_strtoupper') && function_exists('mb_substr') && !empty($string)) {
        $string = mb_strtolower($string, $e);
        $upper = mb_strtoupper($string, $e);
            preg_match('#(.)#us', $upper, $matches);
            $string = $matches[1] . mb_substr($string, 1, mb_strlen($string, $e), $e);
    }
    else {
        $string = ucfirst($string);
    }
    return $string;
}
///HAM CHUYEN CHU HOA THANH CHU THUONG
function strtolower_utf8($string){
    $string=my_ucfirst(mb_strtolower($string,'UTF-8'));
    return $string;
}
///HAM CHUYEN  CHU THUONG thành CHU HOA 
function strtoupper_utf8($string){
    $string=mb_strtoupper($string,'UTF-8');
    return $string;
}
//LOC HACK
function anti_sql($sql) {
    $sql = str_replace(sql_regcase("/(from|select|insert|delete|where|drop table|show tables|#|*|--|\)/"),"",$sql);
    return trim(strip_tags(addslashes($sql))); #strtolower()
}

//Thay đổi kích thước file (thumbs)
//ví dụ File gốc là D:/1.jpg ,file resize là D:/thumbs/1.jpg
//$tmpname => tên file gốc cần resize
//$save_dir => tên thư mục chứa file
//$ah => Chiều cao cần resize(để auto nếu muốn tự động thay đổi tỷ lệ theo chiều rộng)
//$aw => Chiều rộng cần resize(để auto nếu muốn tự động thay đổi tỷ lệ theo chiều cao)
//Lưu ý chỉ một trong 2 tham số $aw và $ah để auto

function img_resize( $tmpname,$save_dir,$ah,$aw,$dir) {
$save_dir .= ( substr($save_dir,-1) != "/") ? "/" : "";
$gis = getimagesize($save_dir.$tmpname);
$type = $gis[2];
switch($type) {
case "1": $imorig = imagecreatefromgif($save_dir.$tmpname); break;
case "2": $imorig = imagecreatefromjpeg($save_dir.$tmpname);break;
case "3": $imorig = imagecreatefrompng($save_dir.$tmpname); break;
default: $imorig = imagecreatefromjpeg($save_dir.$tmpname);
}
$x = imagesx($imorig);
$y = imagesy($imorig);
if($ah=='auto' && is_numeric($aw)){
$ah=($aw/$x*100)*($y/100);
}
if($aw=='auto' && is_numeric($ah)){
$aw=($ah/$y*100)*($x/100);
}
$im = imagecreatetruecolor($aw,$ah);
if (imagecopyresampled($im,$imorig , 0,0,0,0,$aw,$ah,$x,$y)) {imagejpeg($im, $save_dir.$dir.$tmpname);}
}  
?>